package com.example.mybatisplus.HelloController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.entity.User;
import com.example.mybatisplus.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author deyou
 * @Date 2022/1/12 11:11
 * @Version 1.0
 */
@RestController
public class UserController {
    @Autowired
    private IUserService userService;

    /**
     *
     * @param currentPage   设置当前页面
     * @param pageSize      设置页面尺寸
     * @return
     */
    //http://localhost:8080/findPage?currentPage=1&pageSize=2
    @GetMapping("/findPage")
    public List<User> findPage(int currentPage,int pageSize){
        Page<User> userPage = new Page<>();
        //设置当前页面
        userPage.setCurrent(currentPage);
        //设置页面尺寸
        userPage.setSize(pageSize);
        IPage<User> userIPage = userService.selectUserPage(userPage);
        List<User> records = userIPage.getRecords();
        return records;
    }
}
